<?php

class AuthItemDataProvider extends CDataProvider
{
    public $auth;
    public $type;
    public $authItems;
    
    public function __construct(CAuthManager $auth, $type)
    {
        $this->auth = $auth;
        $this->type = $type;
    }

    public function getAuthItems()
    {
        if(empty($this->authItems))
        {
            $this->authItems = $this->auth->getAuthItems($this->type);
            foreach($this->authItems as $authItem)
                $authItem->attachBehavior('authItemBehavior', new AuthItemBehavior);
        }
        
        return $this->authItems;
    }
    
    public function fetchData()
    {
        return array_values($this->getAuthItems());
    }
    
    public function fetchKeys()
    {
        return array_keys($this->getAuthItems());
    }
    
    public function calculateTotalItemCount()
    {
        return count($this->getAuthItems());
    }
}